@echo off

if "%1" == "" goto usage
set BROWSERMODE=*%1

if "%BROWSERMODE%" == "*firefox" set SECONDBROWSER=*googlechrome
if "%BROWSERMODE%" neq "*firefox" set SECONDBROWSER=*firefox

if "%2" == "" (
   if "%OrchardService%" == "iis" set ORCHARDSITE=http://localhost
   if "%OrchardService%" == "webdev" set ORCHARDSITE=http://localhost:30320
)
if "%2" NEQ "" set ORCHARDSITE=%2

if "%3"== "" set TestToRun=automation
if "%3" NEQ "" set TestToRun=automation/%3

if "%4" == "" set SELENIUMHOST=localhost
if "%4" NEQ "" set SELENIUMHOST=%4

if "%5" == "" set SELENIUMPORT=4444
if "%5" NEQ "" set SELENIUMPORT=%5

echo 1.----------Start selenium server by java-----------
start java -jar %seleniumServer% -forcedBrowserMode %BROWSERMODE%
echo.

echo 2.----------Begin to run cases on %BROWSERMODE%----------
if not exist %OrchardQA%\Orchard.Test\TestResults mkdir %OrchardQA%\Orchard.Test\TestResults
if exist %OrchardQA%\Orchard.Test\TestResults\%OrchardService%_%3_%1.trx del /F /Q %OrchardQA%\Orchard.Test\TestResults\%OrchardService%_%3_%1.trx
mstest /runconfig:%OrchardQA%\Orchard.Test\TestRunConfig.testrunconfig /testmetadata:%OrchardQA%\Orchard.Test\Orchard.Test.vsmdi /testlist:%TestToRun% /resultsfile:%OrchardQA%\Orchard.Test\TestResults\%OrchardService%_%3_%1.trx
goto eof

:usage
echo Usage
echo runtest [Browser Mode] [Orchard Site] [Tests to Run] [Selenium Host] [Selenium Port] 
echo.
echo This batch program starts selenium RC and runs automation tests 
echo.
echo Browser Mode (first parameter)
echo     firefox - run tests in firefox
echo     iexplore - run tests in internet explore
echo     googlechrome - run tests in google chrome
echo     opera - run tests in opera
echo.
echo Orchard Site (second parameter)
echo     Orchard site url, if you are host the site under IIS, the default value
echo     is http://localhost; if run the cases against MAC platform, it should be the 
echo      http://[orchard site server name or IP]
echo.
echo Tests to Run (third parameter)
echo      automation test cases specified to run, e.g. automation(all automation test cases) or blogs(automation test cases of Orchard.Blogs)
echo.
echo Selenium Host (forth parameter)
echo     Please provide the machine IP address which hosts selenium RC
echo     The default value is localhost
echo.
echo Selenium Port (fifth parameter)
echo     Port number of selenum RC, the default value is 4444
echo.


:eof